package com.xunyin.modules.mtgoods.service.mapper;


import com.xunyin.common.mapper.CoreMapper;
import com.xunyin.modules.mtgoods.domain.MtGoods;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;


/**
 * 商品 Mapper 接口
 * Copyright (C) 2022-2023
 * All rights reserved, Designed By www.tonetn.com
 * 注意：
 * 本软件为讯音云商开发研制，未经购买不得使用
 * 购买后可获得全部源代码（禁止转卖、分享、上传到码云、github等开源平台）
 * 一经发现盗用、分享等行为，将追究法律责任，后果自负
 */
public interface MtGoodsMapper extends CoreMapper<MtGoods> {


    @Select("<script> select * from mt_goods t " +
            "  where (t.STORE_ID = #{storeId} or t.STORE_ID = 0) and t.STATUS = 'A' order by t.sort asc " +
            " </script>")
    List<MtGoods> getStoreGoodsList(@Param("storeId") Integer storeId);

    @Select("<script> select * from mt_goods t where t.STATUS = 'A' " +
            "   <if test=\"storeId != null and storeId > 0\"> " +
            " and t.STORE_ID = #{storeId} " +
            " </if> " +
            " and (t.name like concat('%',#{keyword},'%') or t.goods_no = #{keyword} or t.ID = #{keyword} or t.description like concat('%',#{keyword},'%')) "+
            " order by t.sort asc </script>")
    List<MtGoods> searchStoreGoodsList(@Param("storeId") Integer storeId, @Param("keyword") String keyword);

    @Select("select * from mt_goods t where t.GOODS_NO = #{goodsNo} and t.STATUS = 'A'")
    MtGoods getByGoodsNo(@Param("goodsNo") String goodsNo);

    @Update("update mt_goods t set t.INIT_SALE = t.INIT_SALE + 1 where t.ID = #{goodsId}")
    Boolean updateInitSale(@Param("goodsId") Integer goodsId);

}
